package common

// *******************************************************
const (
	// 作业类型
	JobTypeManual = "手动执行"
	JobTypeCron   = "定时执行"

	// 步骤类型
	StepTypeExecTask       = "任务"
	StepTypeManualReview   = "人工处理"
	StepTypeProcessControl = "流程控制"
)

// *********************** 作业执行状态 ********************************
type JobCode string

const (
	JOB_STARTING              JobCode = "0"
	JOB_RUNNING               JobCode = "1"
	JOB_SUCCESS               JobCode = "2"
	JOB_AWAITING_CONFIRMATION JobCode = "3"
	JOB_WAITING_TO_RUN        JobCode = "4"
	JOB_EXECUTION_TIMEOUT     JobCode = "5"
	JOB_ORCHESTRATION_ERROR   JobCode = "6"
	JOB_CANCELED              JobCode = "7"
	JOB_TERMINATED            JobCode = "8"
	JOB_EXECUTION_ERROR       JobCode = "9"
)

var jobCodeMap = map[JobCode]string{
	JOB_STARTING:              "开始执行",
	JOB_RUNNING:               "执行中",
	JOB_SUCCESS:               "执行成功",
	JOB_AWAITING_CONFIRMATION: "等待确认",
	JOB_WAITING_TO_RUN:        "等待执行",
	JOB_EXECUTION_TIMEOUT:     "执行超时",
	JOB_ORCHESTRATION_ERROR:   "编排错误",
	JOB_CANCELED:              "已取消",
	JOB_TERMINATED:            "执行终止",
	JOB_EXECUTION_ERROR:       "执行错误",
}

func (jc JobCode) String() string {
	return jobCodeMap[jc]
}

func Code(cn string) JobCode {
	for code, desc := range jobCodeMap {
		if desc == cn {
			return code
		}
	}
	return ""
}

// *********************** 步骤执行状态 ********************************
type SubStepJobCode string

const (
	SUB_STEP_JOB_STARTING              SubStepJobCode = "0"
	SUB_STEP_JOB_RUNNING               SubStepJobCode = "1"
	SUB_STEP_JOB_SUCCESS               SubStepJobCode = "2"
	SUB_STEP_JOB_AWAITING_CONFIRMATION SubStepJobCode = "3"
	SUB_STEP_JOB_WAITING_TO_RUN        SubStepJobCode = "4"
	SUB_STEP_JOB_EXECUTION_TIMEOUT     SubStepJobCode = "5"
	SUB_STEP_JOB_ORCHESTRATION_ERROR   SubStepJobCode = "6"
	SUB_STEP_JOB_CANCELED              SubStepJobCode = "7"
	SUB_STEP_JOB_TERMINATED            SubStepJobCode = "8"
	SUB_STEP_JOB_EXECUTION_ERROR       SubStepJobCode = "9"
)

var subStepJobCodeMap = map[SubStepJobCode]string{
	SUB_STEP_JOB_STARTING:              "开始执行",
	SUB_STEP_JOB_RUNNING:               "执行中",
	SUB_STEP_JOB_SUCCESS:               "执行成功",
	SUB_STEP_JOB_AWAITING_CONFIRMATION: "等待确认",
	SUB_STEP_JOB_WAITING_TO_RUN:        "等待执行",
	SUB_STEP_JOB_EXECUTION_TIMEOUT:     "执行超时",
	SUB_STEP_JOB_ORCHESTRATION_ERROR:   "编排错误",
	SUB_STEP_JOB_CANCELED:              "已取消",
	SUB_STEP_JOB_TERMINATED:            "执行终止",
	SUB_STEP_JOB_EXECUTION_ERROR:       "执行错误",
}

func (ssjc SubStepJobCode) String() string {
	return subStepJobCodeMap[ssjc]
}
